package com.candy.candymember.controller;

import com.candy.candycommon.utils.ResultBean;
import com.candy.candyshortlinkservice.dto.ShortLinkDTO;
import com.candy.candyshortlinkservice.service.DubboShortLinkService;
import com.candy.candyshortlinkservice.service.ShortLinkService;
import lombok.extern.slf4j.Slf4j;
//import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author suYanLong
 * @version 1.0
 * @date 2023/5/31 17:06
 * @Description 支持dubbo、rest同时存在
 */
@Slf4j
@RestController
@RequestMapping("testShortLink")
//@AllArgsConstructor @DubboReference 这两个不能一起使用
public class TestShortLinkController {

    @Autowired
    ShortLinkService shortLinkService;

//    @DubboReference(check = false)
    DubboShortLinkService dubboShortLinkService;

    // http://localhost:8087/testShortLink/getRest
    @GetMapping("getRest")
    public ResultBean getRest() {
        log.info("=============getRest============");
        ShortLinkDTO logLinkDTO = new ShortLinkDTO();
        logLinkDTO.setSourceUrl("https://baidu.com");
        ResultBean convert = shortLinkService.convert(logLinkDTO);
        log.info(convert.getData().toString());
        return convert;
    }

    // http://localhost:8087/testShortLink/getDubbo
    @GetMapping("getDubbo")
    public ResultBean getDubbo() {
        log.info("=============getDubbo============");
        ShortLinkDTO logLinkDTO = new ShortLinkDTO();
        logLinkDTO.setSourceUrl("https://baidu.com");
        ResultBean convert = dubboShortLinkService.convert(logLinkDTO);
        log.info(convert.getData().toString());
        return convert;
    }

}
